/*
 * Copyright (c) 2018 maoyan.com
 * All rights reserved.
 *
 */
package com.darren.archive.repository;

import com.darren.archive.entity.SysUser;
import com.darren.framework.repository.GenericRepository;
import com.darren.framework.utils.Constant;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 系统用户操作持久层
 *
 * @author darren
 * @created 2019/12/12
 */
public interface SysUserRepository extends GenericRepository<SysUser, Long> {

    List<SysUser> findByNameLikeAndEditable(String name, Boolean editable);

    Page<SysUser> findByNameLikeAndEditable(String name, Boolean editable, Pageable pageable);

    Page<SysUser> findByEditable(Boolean editable, Pageable pageable);


    @Modifying
    @Transactional
    @Query(value = " update " + Constant.TABLE_NAME_PREV + "users SET password = ?1 where  id = ?2  ", nativeQuery = true)
    Integer updatePassword(String password, Long id);

    @Modifying
    @Transactional
    @Query(value = " update " + Constant.TABLE_NAME_PREV + "users SET password = :password where  id = :id  ", nativeQuery = true)
    Integer updatePassword(@Param("id") Long id, @Param("password") String password);


}

